/*	Renegade Scripts.dll
	Scripts by zunnie - mp-gaming.com
	Copyright 2010 zunnie

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it 
	under the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code 
	with any closed source module that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#include "z_m02.h"

void z_M02_PowerPlant::Created(GameObject *obj)
{
	sendmsg = false;
	playsnd = true;
	ppdead = false;
	dsnd = true;
}
void z_M02_PowerPlant::Damaged(GameObject *obj, GameObject *damager, float damage)
{
	if (Commands->Get_Health(obj) <= 1.0f)
	{
		ppdead = true;
		sendmsg = true;
		damage = 0.0f;
		Commands->Set_Health(obj,1.0f);
		if (ppdead)
		{
			if (dsnd)
			{	
				dsnd = false;
				Commands->Start_Timer(obj,this,2.5f,201);
			}
		}
		if (sendmsg)
		{
			sendmsg = false;
			Commands->Send_Custom_Event(obj,Commands->Find_Object(Get_Int_Parameter("ObiID")),1000,1,1.0f);
		}
	}
	if (!ppdead)
	{
		if (playsnd)
		{
			Commands->Start_Timer(obj,this,20.0f,200);
			Commands->Start_Timer(obj,this,0.1f,100);
			playsnd = false;
		}
	}
}
void z_M02_PowerPlant::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Send_Message(255,204,0,"The Nod Powerplant is being repaired internally.");
		Commands->Create_2D_WAV_Sound("internalrepair_pp.wav");
		Commands->Start_Timer(obj,this,3.5f,101);
	}
	else if (number == 101)
	{
		Send_Message(255,204,0,"External destruction is not possible.");
		Commands->Create_2D_WAV_Sound("extdestructionnotpossible.wav");
	}
	else if (number == 200)
	{
		playsnd = true;
	}
	else if (number == 201)
	{
		Send_Message(255,204,0,"Nod Base Power is Offline");
		Commands->Create_2D_WAV_Sound("nodbasepowerisoffline.wav");
	}
}
void z_M02_PowerPlant::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&sendmsg);
	Auto_Save_Variable(1,5,&playsnd);
	Auto_Save_Variable(1,5,&ppdead);
	Auto_Save_Variable(1,5,&dsnd);
}

void z_M02_Obelisk::Created(GameObject *obj)
{
	playsnd = true;
	obidead = false;
}
void z_M02_Obelisk::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)
	{
		if (param == 1)
		{
			Commands->Set_Building_Power(obj, false);
		}
	}
}
void z_M02_Obelisk::Damaged(GameObject *obj, GameObject *damager, float damage)
{
	if (!obidead)
	{
		if (playsnd)
		{
			playsnd = false;
			Commands->Start_Timer(obj,this,0.1f,100);
			Commands->Start_Timer(obj,this,20.0f,200);
		}
	}
}
void z_M02_Obelisk::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Send_Message(255,204,0,"The Nod Obelisk is being repaired internally.");
		Commands->Create_2D_WAV_Sound("internalrepair_obi.wav");
		Commands->Start_Timer(obj,this,2.5f,101);
	}
	else if (number == 101)
	{
		Send_Message(255,204,0,"External destruction is not possible.");
		Commands->Create_2D_WAV_Sound("extdestructionnotpossible.wav");
	}
	else if (number == 200)
	{
		playsnd = true;
	}
	else if (number == 300)
	{
		Send_Message(255,204,0,"Nod Obelisk Destroyed");
		Commands->Create_2D_WAV_Sound("m00bnol_kill0002i1evag_snd.wav");
		Commands->Start_Timer(obj,this,3.5f,301);
	}
	else if (number == 301)
	{
		Send_Message(255,204,0,"The Obelisk is down. You should be able to approach it safely.");
		Commands->Create_2D_WAV_Sound("locke_obi_down_m02.wav");
	}
}
void z_M02_Obelisk::Killed(GameObject *obj, GameObject *shooter)
{
	Commands->Start_Timer(obj,this,2.5f,300);
}
void z_M02_Obelisk::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&playsnd);
	Auto_Save_Variable(1,5,&obidead);
}

void z_M02_bay_teleportzone::Created(GameObject *obj)
{
	tele = false;
}
void z_M02_bay_teleportzone::Entered(GameObject *obj, GameObject *enter)
{
	if (tele)
	{
		tele = false;//short pause so people dont get stuck in each other when teleporting
		Vector3 pos1 = Commands->Get_Position(Commands->Find_Object(Get_Int_Parameter("ID1")));
		Vector3 pos2 = Commands->Get_Position(Commands->Find_Object(Get_Int_Parameter("ID2")));
		Vector3 pos3 = Commands->Get_Position(Commands->Find_Object(Get_Int_Parameter("ID3")));
		int random = Commands->Get_Random_Int(1,3);
		if (random == 1)
		{
			Commands->Set_Position(enter,pos1);
		}
		else if (random == 2)
		{
			Commands->Set_Position(enter,pos2);
		}
		else if (random == 3)
		{
			Commands->Set_Position(enter,pos3);
		}
		Commands->Start_Timer(obj,this,2.5f,100);//enable tele again
	}
}
void z_M02_bay_teleportzone::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)
	{
		if (param == 1)
		{
			tele = true;
		}
	}
}
void z_M02_bay_teleportzone::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		tele = true;
	}
}
void z_M02_bay_teleportzone::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&tele);
}

void z_M02_Nod_Helipad::Created(GameObject *obj)
{
	playdead = true;
	playdmg = true;
	dead = false;
}
void z_M02_Nod_Helipad::Killed(GameObject *obj, GameObject *shooter)
{
	dead = true;
	playdmg = false;
	Send_Message(255,204,0,"Nod Helicopter Pad destroyed.");
	Commands->Create_2D_WAV_Sound("m00bnhp_kill0002i1evag_snd.wav");
	Commands->Start_Timer(obj,this,3.5f,102);//good work
}
void z_M02_Nod_Helipad::Damaged(GameObject *obj, GameObject *damager, float damage)
{
	if (!dead)
	{
		if (playdmg)
		{
			playdmg = false;
			Commands->Start_Timer(obj,this,0.1f,100);//playdmg
			Commands->Start_Timer(obj,this,20.0f,101);//enable dmg play
		}
	}
}
void z_M02_Nod_Helipad::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		if (!dead)
		{
			Commands->Create_2D_WAV_Sound("m00bnhp_tdfe0002i1evag_snd.wav");
			Send_Message(255,204,0,"Nod Helicopter Pad under attack.");
		}
	}
	else if (number == 101)
	{
		if (!dead)
		{
			playdmg = true;
		}
	}
	else if (number == 102)
	{
		if (dead)
		{
			playdmg = false;
			playdead = false;
			Commands->Create_2D_WAV_Sound("helipaddownnicework.wav");
			Send_Message(255,204,0,"The Helipad is down. Nice work Havoc.");
		}
	}
}
void z_M02_Nod_Helipad::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&playdead);
	Auto_Save_Variable(1,5,&dead);
	Auto_Save_Variable(1,5,&playdmg);
}

void z_M02_MissionStart::Created(GameObject *obj)
{
	Commands->Start_Timer(obj,this,5.0f,101);//find scientists
	Commands->Start_Timer(obj,this,9.0f,102);//hummvee to get started
	Commands->Start_Timer(obj,this,11.5f,103);//got anything bigger?
}
void z_M02_MissionStart::Timer_Expired(GameObject *obj, int number)
{
	if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("locke_locatescientists.wav");
		Send_Message(255,204,0,"Havoc locate the Nod Base Facility and recover the Scientists.");
	}
	else if (number == 102)
	{
		Commands->Create_2D_WAV_Sound("locke_herehummgetstarted.wav");
		Send_Message(255,204,0,"Here's a hummvee to get your started.");
	}
	else if (number == 103)
	{
		Commands->Create_2D_WAV_Sound("m02dsgn_dsgn0002r1gbmg_snd.wav");
		Send_Message(255,204,0,"Got anything bigger? Hummvee's are not my style.");
	}
}

void z_M02_ObjectiveCtrl1::Created(GameObject *obj)
{
	play = true;
}
void z_M02_ObjectiveCtrl1::Entered(GameObject *obj, GameObject *enter)
{
	if (Commands->Is_A_Star(enter))
	{
		if (play)
		{
			play = false;
			Commands->Start_Timer(obj,this,0.1f,101);
		}
	}
}
void z_M02_ObjectiveCtrl1::Timer_Expired(GameObject *obj, int number)
{
	if (number == 101)
	{
		Commands->Start_Timer(obj,this,6.5f,102);
		Commands->Create_2D_WAV_Sound("eliminatehelipad.wav");
		Send_Message(255,204,0,"That Nod Helipad will allow Apache's to reinforce. You would be better of if you eliminate it.");
	}
	else if (number == 102)
	{
		Commands->Start_Timer(obj,this,7.0f,103);
		Commands->Create_2D_WAV_Sound("elimiateofficerresistanceoccupytower.wav");
		Send_Message(255,204,0,"Looks like has an Officer coordinating reinforcements in that Guard Tower. Eliminate all resistance and occupy the tower.");
		
	}
	else if (number == 103)
	{
		Commands->Start_Timer(obj,this,2.5f,104);
		Commands->Create_2D_WAV_Sound("objective3new.wav");
		Send_Message(255,204,0,"New Tertiary Mission Objective");
	}
	else if (number == 104)
	{
		Commands->Start_Timer(obj,this,2.5f,105);
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"Destroy the Nod Helicopter Pad.");
	}
	else if (number == 105)
	{
		Commands->Start_Timer(obj,this,2.5f,106);
		Commands->Create_2D_WAV_Sound("objective2new.wav");
		Send_Message(255,204,0,"New Secondary Mission Objective");
	}
	else if (number == 106)
	{
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"Eliminate Nod forces and occupy the Guard Tower.");
	}
}
void z_M02_ObjectiveCtrl1::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)//secondary complete
	{
		if (param == 1)
		{
			Commands->Create_2D_WAV_Sound("objective2complete.wav");
			Send_Message(255,204,0,"Secondary Objective Complete.");
			Vector3 ptpos;
			ptpos.X = 134.385f; ptpos.Y = 21.159f; ptpos.Z = -14.245f;
			float facing = 90.000f;
			GameObject *pt;
			pt = Commands->Create_Object("pct_zone_gdi",ptpos);
			Commands->Set_Facing(pt,facing);
		}
	}
	else if (message == 1001)//tertiary complete
	{
		if (param == 1)
		{
			Commands->Create_2D_WAV_Sound("objective3complete.wav");
			Send_Message(255,204,0,"Tertiary Objective Complete.");
		}
	}
}
void z_M02_ObjectiveCtrl1::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&play);
}

void z_M02_ObjectiveCtrl2::Created(GameObject *obj)
{
	play = true;
}
void z_M02_ObjectiveCtrl2::Entered(GameObject *obj, GameObject *enter)
{
	if (play)
	{
		play = false;
		Commands->Create_2D_WAV_Sound("nextobjhousesoccupy.wav");
		Send_Message(255,204,0,"Your next 2 checkpoints are in the houses across the bridge. Eliminate all resistance and occupy the houses.");//actually this can stay here...
		Commands->Enable_Spawner(104908,true);
		//Commands->Enable_Spawner(104909,true);
		Commands->Enable_Spawner(104910,true);
		Commands->Enable_Spawner(104911,true);
		Commands->Enable_Spawner(104912,true);
		Commands->Enable_Spawner(104913,true);
		//Commands->Enable_Spawner(104914,true);
		//Commands->Enable_Spawner(104915,true);
		Commands->Enable_Spawner(104916,true);
		Commands->Enable_Spawner(104917,true);
		Commands->Enable_Spawner(104918,true);
		Commands->Enable_Spawner(104919,true);
		//Commands->Enable_Spawner(104920,true);
		Commands->Enable_Spawner(104921,true);
		Commands->Enable_Spawner(104922,true);
		Commands->Enable_Spawner(104923,true);
		Commands->Enable_Spawner(104924,true);
		Commands->Enable_Spawner(104925,true);
		//Commands->Enable_Spawner(104926,true);
		Commands->Enable_Spawner(104927,true);
		Commands->Enable_Spawner(104928,true);
		Commands->Enable_Spawner(104929,true);
		Commands->Enable_Spawner(104930,true);
		Commands->Enable_Spawner(104931,true);
		Commands->Enable_Spawner(104932,true);
		Commands->Enable_Spawner(104933,true);
	}
}
void z_M02_ObjectiveCtrl2::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&play);
}

void z_M02_ObjectiveCtrl1Reminder::Created(GameObject *obj)
{
	play = true;
}
void z_M02_ObjectiveCtrl1Reminder::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)
	{
		if (param == 1)
		{
			play = false;//the objective in tower was completed so no reminding...
		}
	}
}
void z_M02_ObjectiveCtrl1Reminder::Entered(GameObject *obj, GameObject *enter)
{
	if (play)
	{
		Commands->Create_2D_WAV_Sound("dontoverlooktower.wav");
		Send_Message(255,204,0,"Don't overlook that tower Havoc. We need that checkpoint secure.");
	}
}
void z_M02_ObjectiveCtrl1Reminder::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&play);
}

void z_M02_Objective_Houses_Ctrl::Created(GameObject *obj)//when this object is created apply settings
{
	secures = 0;//no houses were secured yet
	required = 2;//2 houses to secure
	botcount = 0;//bot counter to determine if all bots were killed in area
}
void z_M02_Objective_Houses_Ctrl::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)//increment secures by 1
	{
		if (param == 1)
		{
			secures++;
			if (secures == required)//if secures all done
			{
				Commands->Start_Timer(obj,this,0.1f,102);//houses secured, obj nearly met
			}
		}
	}

	else if (message == 2000)//a bot spawned
	{
		if (param == 1)
		{
			botcount++;
		}
	}
	else if (message == 2001)//a bot died
	{
		if (param == 1)
		{
			botcount--;
			if (botcount == 0)
			{
				Commands->Start_Timer(obj,this,0.1f,101);//all bots in the area are dead, obj complete
			}
		}
	}
}
void z_M02_Objective_Houses_Ctrl::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("eliminateallresistsecureobjective.wav");
		Send_Message(255,204,0,"You'll need to eliminate all the enemy resistance in the area to secure this objective.");
		Commands->Enable_Spawner(104908,false);
		//Commands->Enable_Spawner(104909,false);
		Commands->Enable_Spawner(104910,false);
		Commands->Enable_Spawner(104911,false);
		Commands->Enable_Spawner(104912,false);
		Commands->Enable_Spawner(104913,false);
		//Commands->Enable_Spawner(104914,false);
		//Commands->Enable_Spawner(104915,false);
		Commands->Enable_Spawner(104916,false);
		Commands->Enable_Spawner(104917,false);
		Commands->Enable_Spawner(104918,false);
		Commands->Enable_Spawner(104919,false);
		//Commands->Enable_Spawner(104920,false);
		Commands->Enable_Spawner(104921,false);
		Commands->Enable_Spawner(104922,false);
		Commands->Enable_Spawner(104923,false);
		Commands->Enable_Spawner(104924,false);
		Commands->Enable_Spawner(104925,false);
		//Commands->Enable_Spawner(104926,false);
		Commands->Enable_Spawner(104927,false);
		Commands->Enable_Spawner(104928,false);
		Commands->Enable_Spawner(104929,false);
		Commands->Enable_Spawner(104930,false);
		Commands->Enable_Spawner(104931,false);
		Commands->Enable_Spawner(104932,false);
		Commands->Enable_Spawner(104933,false);
	}
	else if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("objective_seconday_accomplished.wav");
		Send_Message(255,204,0,"Secondary Objective Accomplished");
		Commands->Start_Timer(obj,this,3.5f,103);//lol :D
	}
	else if (number == 102)//houses secured
	{
		Commands->Create_2D_WAV_Sound("m02dsgn_dsgn0058i1eval_snd.wav");
		Send_Message(255,204,0,"Excellent pace Havoc. Make sure both buildings are secure.");
		Commands->Start_Timer(obj,this,3.5f,100);
	}
	else if (number == 103)
	{
		Commands->Create_2D_WAV_Sound("its_a_pleasure_havoc.wav");
		Send_Message(255,204,0,"It's a pleasure to see you at work Havoc.");
	}
}
void z_M02_Objective_Houses_Ctrl::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&secures);//we must remember their state...
	Auto_Save_Variable(1,5,&required);
	Auto_Save_Variable(1,5,&botcount);
}



ScriptRegistrant<z_M02_Objective_Houses_Ctrl> z_M02_Objective_Houses_Ctrl_Registrant("z_M02_Objective_Houses_Ctrl","");
ScriptRegistrant<z_M02_ObjectiveCtrl1Reminder> z_M02_ObjectiveCtrl1Reminder_Registrant("z_M02_ObjectiveCtrl1Reminder","");
ScriptRegistrant<z_M02_ObjectiveCtrl2> z_M02_ObjectiveCtrl2_Registrant("z_M02_ObjectiveCtrl2","");
ScriptRegistrant<z_M02_ObjectiveCtrl1> z_M02_ObjectiveCtrl1_Registrant("z_M02_ObjectiveCtrl1","");
ScriptRegistrant<z_M02_MissionStart> z_M02_MissionStart_Registrant("z_M02_MissionStart","");
ScriptRegistrant<z_M02_Nod_Helipad> z_M02_Nod_Helipad_Registrant("z_M02_Nod_Helipad","");
ScriptRegistrant<z_M02_Obelisk> z_M02_Obelisk_Registrant("z_M02_Obelisk","");
ScriptRegistrant<z_M02_PowerPlant> z_M02_PowerPlant_Registrant("z_M02_PowerPlant","ObiID=1:int");